package com.ljl.mvvmdemo.util

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

/**
 * 数据库类对象转换工具
 * created by luojialun on 2024/10/23
 */
class StringConverter {
    private val type: Type = object : TypeToken<List<String>>() {}.type

    @TypeConverter
    fun stringToString(json: String?): List<String>? {
        return json?.let { GsonUtils.getInstance().fromJson(it, type) }
    }

    @TypeConverter
    fun stringToString(stringList: List<String>?): String? {
        return stringList?.let { GsonUtils.getInstance().toJson(it) }
    }

}